﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Samples.Kinect.BodyBasics.Controls
{
    public class Package
    {
        //发送的字节数组
        private byte[] sendBuffer;
        //这里不需要应答
        //private byte[] receiveBuffer;

        //发送的序号
        private static long sendTick = 0;

        public byte[] SendBuffer { get => sendBuffer; set => sendBuffer = value; }
        public static long SendTick { get => sendTick; }

        //使用工厂模式
        private Package()
        {
            sendTick++;

        }

        public static Package AddPackage(string strSend)
        {
            Package package = new Package();
            //需要测试这里的输出

            string str = strSend/* + "\r\n"*/;
            byte[] bytesSend = System.Text.ASCIIEncoding.ASCII.GetBytes(str.ToArray());
            package.SendBuffer = new byte[bytesSend.Length + 2];
            Array.Copy(bytesSend, 0, package.SendBuffer, 0, bytesSend.Length);
            package.SendBuffer[package.SendBuffer.Length - 2] = 0x0d;
            package.SendBuffer[package.SendBuffer.Length - 1] = 0x0a;

            Console.WriteLine("strSend : " + str);

            //test
            Console.Write("sendBuffer : ");

            foreach (byte b in package.SendBuffer)
            {
                Console.Write(" " + b.ToString("x"));
            }
            Console.WriteLine();

            return package;

        }

        public static Package AddPackage(byte[] bytesSend)
        {
            Package package = new Package();
            package.SendBuffer = bytesSend;

            return package;
        }

        //public byte[] GetBytes()
        //{
        //    return SendBuffer;
        //}

        


    }
}
